# _*_ coding: utf8 _*_
# Create your views here.
import copy

from django.http import HttpResponse, JsonResponse

from common.serializers import VideoSeri


def video_upload(request):
    try:
        video_data = copy.deepcopy(request.POST)
        video_data['user'] = request.user.pk
        video_data['url'] = request.FILES.get('video', None)
        video_data['cover'] = request.FILES.get('cover', None)
        seri = VideoSeri(data=video_data)
        if seri.is_valid(raise_exception=True):
            seri.save()
        else:
            return JsonResponse({'code': 622, 'msg': u'无效的参数'})
    except Exception as e:
        return JsonResponse({'code': 622, 'msg': str(e)})
    return HttpResponse()